#!/bin/bash
#chkconfig: 345 20 80
# description: wasservice 

WAS_DIR=/opt/IBM/WebSphere/AppServer
WAS_PROCESS=$WAS_DIR/java
serverName=server1

function startWASServer {
	current_process=$(ps -ef |grep $WAS_PROCESS |grep $serverName |grep -v grep | awk '{print $2}')
	if [ "$current_process" != "" ]; then
		echo "...WAS server is already running"
	else 
		echo "...starting WAS server"
		${WAS_DIR}/bin/startServer.sh $serverName
	fi
}

function stopWASServer {
	current_process=$(ps -ef |grep $WAS_PROCESS |grep $serverName |grep -v grep | awk '{print $2}')
	if [ "$current_process" != "" ]; then
		echo "...stopping WAS server"
		${WAS_DIR}/bin/stopServer.sh $serverName
	else
		echo "...WAS server not running"
	fi
}

function usage {
	echo "Usage $0 {start|stop|restart}"
}

case "$1" in 
	start) 
		startWASServer 
	;;
	stop)
		stopWASServer
	;;
	restart)
		stopWASServer
		startWASServer
	;;
	*)
		usage
	;;
esac